userList=[];

application.onAppStart=function()
{
	trace("fms服务器启动......");
}

application.onConnect = function(currentClient)
{
	application.acceptConnection(currentClient);
	if (userList.length>=3)
	{
		currentClient.call("showServerMsg",null,"已经达到最大用户数");
		application.rejectConnection(currentClient);
	}
	else
	{                 
		currentClient.communicateServer= function(value)
		{
			currentClient.username=value;
			trace(currentClient.username+"加入聊天室");
			userList.push(value);
			trace("当前用户列表"+userList);
			application.broadcastMsg("playOtherVideo",userList);
		}
	}
}

application.onDisconnect=function(currentClient)
{
	trace("用户"+currentClient.username+"离开聊天室");
	
	for(j=0;j<userList.length;j++)
	{
		if ( userList[j]==currentClient.username )
		{
			userList.splice(j,1);
		}
	}
	trace("当前用户列表"+userList);
	application.broadcastMsg("playOtherVideo",userList);
}